package com.xio.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.xio.cloud.handler.CustomerBlockHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xio
 * @Description: 控制层
 * @Date: 2021/3/21 11:57
 */
@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
        return "- - - -Test A";
    }

    @GetMapping("/testB")
    public String testB() {
        return "- - - -Test B";
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                        @RequestParam(value = "p2", required = false) String p2) {
        return "testHotKey ok";
    }

    public String deal_testHotKey(String p1, String p2, BlockException exception) {
        return "- - - - It's Error - - - -";
    }

    // @SentinelResource(value="") sentinel可根据此注解配置的资源名或者接口url来限流  url: /testC  资源名:testC
    @GetMapping("/testC")
    @SentinelResource(value = "testC", blockHandlerClass = CustomerBlockHandler.class, blockHandler = "handleStrException")
    public String testC() {
        return "testC ok";
    }



}
